﻿#region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
#endregion

namespace DirectZZT.Components
{
    /// <summary>
    /// The FPS counter.
    /// </summary>
    public class FPSComponent : DrawableGameComponent
    {
        private SpriteFont _font;
        private SpriteBatch _sprite;

        public FPSComponent(Game game)
            : base(game)
        {

        }

        protected override void LoadContent()
        {
            base.LoadContent();
        }

        public override void Initialize()
        {
            base.Initialize();


            _font = this.Game.Content.Load<SpriteFont>("Fonts/DiagnosticsFont");
            _sprite = new SpriteBatch(this.Game.GraphicsDevice);
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);

            _sprite.Begin();
            _sprite.DrawString(_font, string.Format("FPS: {0:0}", 1000 / gameTime.ElapsedGameTime.TotalMilliseconds), new Vector2(8, 8), Color.White);
            _sprite.End();
        }
    }
}
